using UnityEngine;
using System.Collections;

public class LifeBar : MonoBehaviour {
	
	public Xwing player;
	public Texture EnergyBar;
	
	float lastTime = 0, tick = 5;
	
	void OnGUI()
	{
		if (player.FullLife <= 0) 
		{
			Debug.Log("A vida do jogador é zero. Coloque um valor superior");
			return;
		}
		
		float barPercent = (float)player.Life/ player.FullLife;
		
		GUI.DrawTexture(new Rect(48, 23, EnergyBar.width * 0.105f * barPercent, EnergyBar.height * 0.08f), EnergyBar);
		//Debug.Log(player.Life);
		Debug.Log(barPercent);
		
		if (lastTime + tick < Time.time)
		{
			lastTime = Time.time;
			player.Hurt(1);
		}
	}
}
